//
//  MainViewController.swift
//  KKWB
//
//  Created by KSY-iOS on 17/1/6.
//  Copyright © 2017年 KK. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    
    fileprivate lazy var composeBtn: UIButton = UIButton(imageName: "tabbar_compose_icon_add", bgImageName: "tabbar_compose_button")
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupComposeBtn()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
//        setupTabbarItmes()
    }
    
}

// MARK:- 设置UI界面
extension MainViewController {
    
    fileprivate func setupComposeBtn() {
    
        // 添加 + 按钮
        tabBar.addSubview(composeBtn)

        composeBtn.center = CGPoint(x: tabBar.center.x, y: tabBar.bounds.size.height / 2)
        composeBtn.addTarget(self, action: #selector(composeBtnClick), for: .touchUpInside)
    }
    
    fileprivate func setupTabbarItmes() {
    
        for i in 0..<tabBar.items!.count {
            
            let item = tabBar.items![i]
            
            if i == 2 {
                item.isEnabled = false
                break
            }
        }
    }
}

// 时间监听
extension MainViewController {
    
    @objc fileprivate func composeBtnClick() {
        
        let composeVc = ComposeViewController()
        let composeNav = UINavigationController(rootViewController: composeVc)
        
        present(composeNav, animated: true, completion: nil)
        
        
    }
}
